package com.witdata.common.service.impl;

import com.mybatisflex.core.query.QueryWrapper;
import com.witdata.mysql.base.service.UserInstanceBaseService;
import com.witdata.mysql.domain.entity.TUserInstance;
import com.witdata.common.domain.dto.UserInstanceDto;
import com.witdata.common.mapper.UserMapper;
import com.witdata.common.service.OnlineCodeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class OnlineCodeServiceImpl implements OnlineCodeService {
    private final UserInstanceBaseService userInstanceBaseService;

    @Override
    public List<UserInstanceDto> getUserInstanceList(Long userId) {
        List<TUserInstance> tUserInstanceList = userInstanceBaseService.list(new QueryWrapper().eq("user_id", userId));
        return UserMapper.INSTANCE.toUserInstanceDtoList(tUserInstanceList);
    }

    @Override
    public void createUserInstance(UserInstanceDto userInstanceDto) {
//        String name = UUID.randomUUID().toString().replace("-", "");
//        Container container = dockerService.createContainer(userInstanceDto.getInstanceId(), userInstanceDto.getImageId(), name);
//        TUserInstance tUserInstance = UserMapper.INSTANCE.toTUserInstance(userInstanceDto);
//        tUserInstance.setContainerId(container.getId());
//        tUserInstance.setId(IdUtils.createId());
//        tUserInstance.setCreated(LocalDateTime.now());
//        tUserInstance.setUpdated(LocalDateTime.now());
//        tUserInstance.setDelFlag(false);
//        userInstanceBaseService.save(tUserInstance);
    }
}
